package com.uobgroup.cmt.base.config;

import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * Copyright UOB Ltd. All rights reserved. (2011)
 *
 * This software is the confidential and proprietary information
 * of United Overseas Bank Ltd. ("Confidential Information"). 
 * You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the contract
 * agreement you entered into with UOB.
 * 
 * File Name  : ConfigurationUtil.java
 * Created By : Adelwin Handoyo
 * Created At : Mar 25, 2011 11:48:11 AM
 *
 * Change History
 * Author Name     Date        Details
 * =============== =========== =================================
 * Adelwin Handoyo Mar 25, 2011 Initial Draft
 */

public class ConfigurationUtil {
	protected static Logger logger = Logger.getLogger(ConfigurationUtil.class);
	
	public static final String CONFIG_FILE = "config.properties";
	
	public static final String KEY_SPRING_CONFIGFILELOCATION = "config.spring.configFileLocation";
	
	private Properties configurationProperties = null;
	
	private ConfigurationUtil() {
		try {
			this.configurationProperties = new Properties();
			this.configurationProperties.load(ClassLoader.getSystemResourceAsStream(CONFIG_FILE));
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
			throw new RuntimeException("Error in instantialing a base singleton");
		}
	}
	
	private static class SingletonHolder {
		public static final ConfigurationUtil INSTANCE = new ConfigurationUtil();
	}
	
	public static ConfigurationUtil getInstance() {
		return SingletonHolder.INSTANCE;
	}
	
	public String getConfigurationValue(String key) {
		return this.configurationProperties.getProperty(key);
	}
}
